<?php if (!defined('CORE_DIR')) die('Wrong entry point!');

/* 
 * Copyright 2010 Anton Muraviev a.k.a kuromaisu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

Aero::define('DiffLibrarySpecification', AS_SINGLETON);

/*
 * DiffLibrarySpecification
 */
class DiffLibrarySpecification extends AeroSpec
{
	public function itShouldFindInsertedAndDeletedLines()
	{
		$lib = Aero::load('libs/diff');
		
		$lhs = "Line 1.\nLine 2.\nLine 3.";
		$rhs = "Line 1.\nLine 3.";
		
		$diff = $lib->diff($lhs, $rhs);
		
		$this->variable($diff[0][0])
			->equals($diff[1][0])
			->equals(array(DIFF_OP_COPY,'Line 1.'));
		
		$this->variable($diff[0][1])->equals(array(DIFF_OP_DELETE,'Line 2.'));
		$this->variable($diff[1][1])->equals(array(DIFF_OP_DELETE,'&nbsp;'));

	}
	
	protected function itShouldFindInlineDifferences($value='')
	{
		$lib = Aero::load('libs/diff');
		
		$test_1_old = 'Example string.';
		$test_1_new = 'Sample string.';
		
		// No differences
		$diff = $lib->diff($test_1_old, $test_1_old, DIFF_MODE_WORD);
		
		$this->variable($diff[0])->equals($diff[1]);
		
		// Some differences
		$diff = $lib->diff($test_1_old, $test_1_new, DIFF_MODE_WORD);
		
		$this->variable($diff[0][0])->equals(array(DIFF_OP_DELETE,'Example'));
		$this->variable($diff[1][0])->equals(array(DIFF_OP_ADD,'Sample'));

		$this->variable($diff[0][2])->equals($diff[1][2])->equals(array(DIFF_OP_COPY,'string'));
		
	}
}